﻿using System.Threading.Tasks;
using Hopscotch.Common.Logging;
using Microsoft.AspNet.SignalR;

namespace Hopscotch.Server.EnqSignalRHost.Hubs
{
    public abstract class HubBase : Hub
    {
        protected readonly ILogger logger;

        public HubBase()
        {
            logger = AppLogger.CreateLogger(this.GetType().Name);
        }

        public override Task OnConnected()
        {
            logger.Info("Connected Id={0}", Context.ConnectionId);
            return base.OnConnected();
        }

        public override Task OnDisconnected(bool stopCalled)
        {
            logger.Info("Disconnected Id={0}", Context.ConnectionId);
            return base.OnDisconnected(stopCalled);
        }

        public override Task OnReconnected()
        {
            logger.Info("Reconnected Id={0}", Context.ConnectionId);
            return base.OnReconnected();
        }
    }

    public abstract class HubBase<T> : Hub<T>
        where T : class
    {
        protected readonly ILogger logger;

        public HubBase()
        {
            logger = AppLogger.CreateLogger(this.GetType().Name);
        }

        public override Task OnConnected()
        {
            logger.Info("Connected Id={0}", Context.ConnectionId);
            return base.OnConnected();
        }

        public override Task OnDisconnected(bool stopCalled)
        {
            logger.Info("Disconnected Id={0}", Context.ConnectionId);
            return base.OnDisconnected(stopCalled);
        }

        public override Task OnReconnected()
        {
            logger.Info("Reconnected Id={0}", Context.ConnectionId);
            return base.OnReconnected();
        }
    }
}
